package GUI;

import javax.swing.JOptionPane;
import javax.swing.JPanel;
import java.awt.SystemColor;
import javax.swing.JLabel;
import java.awt.Font;
import javax.swing.JTextField;
import java.awt.Color;
import javax.swing.JButton;

import Client.BusinessImplements;
import Controler.Update_User_Controler;

import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.util.ArrayList;
import javax.swing.border.LineBorder;
/**
* @author Lucie
 * Class name Update_User_first_Panel
 * extend  Abstract_Jpanel
 * purpose: change the details of the author that the user chose
 */
public class Update_User_first_Panel extends Abstract_Jpanel  {
	private JTextField textField;

	/**
	 * Create the panel.
	 */
	public Update_User_first_Panel() {
		setLayout(null);
		
		JPanel panel = new JPanel();
		panel.setBorder(new LineBorder(SystemColor.activeCaption, 6));
		panel.setBackground(SystemColor.inactiveCaption);
		panel.setBounds(36, 55, 415, 221);
		add(panel);
		panel.setLayout(null);
		
		JLabel lblUserId = new JLabel("User Id:");
		lblUserId.setFont(new Font("Tahoma", Font.PLAIN, 14));
		lblUserId.setBounds(39, 72, 61, 14);
		panel.add(lblUserId);
		
		textField = new JTextField();
		textField.setBounds(110, 71, 180, 20);
		panel.add(textField);
		textField.setColumns(10);
		
		JLabel lblChooseUserId = new JLabel("choose user id that you like to update");
		lblChooseUserId.setForeground(Color.RED);
		lblChooseUserId.setFont(new Font("Segoe Print", Font.PLAIN, 13));
		lblChooseUserId.setBounds(50, 112, 261, 14);
		panel.add(lblChooseUserId);
		
		JLabel lblChoseUserId = new JLabel("chose user id to update");
		lblChoseUserId.setForeground(new Color(25, 25, 112));
		lblChoseUserId.setFont(new Font("MV Boli", Font.PLAIN, 30));
		lblChoseUserId.setBounds(51, 11, 383, 47);
		add(lblChoseUserId);
		/*
		 * btnBack goes back to sing in panel
		 */
		JButton btnBack = new JButton("back");
		btnBack.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				Sign_in_panel sip=new Sign_in_panel();
				on_screen_unload();
				BusinessImplements.GetInstance().getMainFrame().setContentPane(sip);
				sip.setSize(getMaximumSize());
				sip.on_screen_load();

				
			}
		});
		btnBack.setFont(new Font("Tahoma", Font.PLAIN, 14));
		btnBack.setBounds(47, 302, 89, 39);
		add(btnBack);
		/*
		 * goes to Update_User_secon_Panel 
		 */
		JButton btnGo = new JButton("go");
		btnGo.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				
				Update_User_Controler update_user_controler=new Update_User_Controler();
				ArrayList<String> str_check=new  ArrayList<String>();
				str_check=update_user_controler.get_user(textField.getText());
				if(str_check!=null)
				{
				Update_User_secon_Panel next_screen=new Update_User_secon_Panel();
				on_screen_unload();
				BusinessImplements.GetInstance().getMainFrame().setContentPane(next_screen);
				next_screen.setSize(getMaximumSize());
				next_screen.on_screen_load(str_check);
				}
				else {
					next_screen_faild(update_user_controler.get_msg());
					
				}
			}
		});
		btnGo.setFont(new Font("Tahoma", Font.PLAIN, 14));
		btnGo.setBounds(362, 302, 89, 39);
		add(btnGo);

	}

	@Override
	public void next_screen() {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void prev_screen() {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void on_screen_load() {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void on_screen_unload() {
		// TODO Auto-generated method stub
		
	}
	/**
	 *  this method display showMessageDialog with a failed msg
	 * @param msg
	 */
	public void next_screen_faild(String msg)
	{
		JOptionPane.showMessageDialog(this,"apply faild "+msg);
	}

}
